package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.CartoonTeacherListClassDataBean;
import com.fancy.learncenter.ui.activity.CartoonTeacherClassDetailActivity;
import com.fancy.learncenter.ui.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.ui.adapter.base.CustomViewHold;

import java.util.List;

/**
 * Created by hyy on 2018/1/24.
 * describe as
 */

public class CartoonTeacherClassListAdapter extends CommonRecycleViewAdapter<CartoonTeacherListClassDataBean.ClassVOBean> {
    public CartoonTeacherClassListAdapter(Context mContext, List<CartoonTeacherListClassDataBean.ClassVOBean> itemDatas) {
        super(mContext, R.layout.activity_teacher_listclass_item, itemDatas);
    }

    @Override
    public void bindView(CustomViewHold customViewHold, final CartoonTeacherListClassDataBean.ClassVOBean item, final int position) {

        TextView name = customViewHold.getView(R.id.name);
        name.setText(item.getClassName());

        TextView school_name = customViewHold.getView(R.id.school_name);
        school_name.setText(item.getSchoolName());

        SimpleDraweeView class_pic = customViewHold.getView(R.id.class_pic);
        class_pic.setImageURI(item.getClassImgurl());

        TextView status = customViewHold.getView(R.id.status);
        TextView complete = customViewHold.getView(R.id.complete);
        TextView total = customViewHold.getView(R.id.total);
        if (TextUtils.isEmpty(item.getHomworkTimeStr())) {
            status.setText("未布置作业");
            complete.setVisibility(View.GONE);
            total.setVisibility(View.GONE);
        } else {
            status.setText("11月10日作业：");
            complete.setText(item.getCommitCount());
            total.setText("/" + item.getTotalCount());
            complete.setVisibility(View.VISIBLE);
            total.setVisibility(View.VISIBLE);
        }


        customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, CartoonTeacherClassDetailActivity.class);

                intent.putExtra(CartoonTeacherClassDetailActivity.CLASS_NAME_KEY, item.getClassName());
                intent.putExtra(CartoonTeacherClassDetailActivity.CLASS_NUM_KEY, item.getClassNo());
                intent.putExtra(CartoonTeacherClassDetailActivity.CLASS_PIC_KEY, item.getClassImgurl());
                intent.putExtra(CartoonTeacherClassDetailActivity.CLASS_ID_KEY, item.getClassId());
                intent.putExtra(CartoonTeacherClassDetailActivity.CLASS_STUDENT_NUM_KEY, item.getRated());

                mContext.startActivity(intent);
            }
        });

        customViewHold.getRoorView().setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                onLongClickCallBack.CallBack(item, position);
                return true;
            }
        });


    }

    public OnLongClickCallBack getOnLongClickCallBack() {
        return onLongClickCallBack;
    }

    public void setOnLongClickCallBack(OnLongClickCallBack onLongClickCallBack) {
        this.onLongClickCallBack = onLongClickCallBack;
    }

    private OnLongClickCallBack onLongClickCallBack;

    public interface OnLongClickCallBack {
        abstract void CallBack(CartoonTeacherListClassDataBean.ClassVOBean item, int position);
    }


}
